from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-07-25 14:08:37.514620
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 25, Jul, 2022
Time: 14:08:44
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.9188
Nobs: 728.000 HQIC: -50.2673
Log likelihood: 9170.11 FPE: 1.18605e-22
AIC: -50.4863 Det(Omega_mle): 1.04900e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.299825 0.056760 5.282 0.000
L1.Burgenland 0.107133 0.037198 2.880 0.004
L1.Kärnten -0.106964 0.019725 -5.423 0.000
L1.Niederösterreich 0.209717 0.077928 2.691 0.007
L1.Oberösterreich 0.106765 0.075945 1.406 0.160
L1.Salzburg 0.253735 0.039797 6.376 0.000
L1.Steiermark 0.042521 0.051925 0.819 0.413
L1.Tirol 0.108320 0.042116 2.572 0.010
L1.Vorarlberg -0.062975 0.036321 -1.734 0.083
L1.Wien 0.047110 0.067197 0.701 0.483
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.054590 0.118612 0.460 0.645
L1.Burgenland -0.031288 0.077734 -0.402 0.687
L1.Kärnten 0.047071 0.041219 1.142 0.253
L1.Niederösterreich -0.177703 0.162848 -1.091 0.275
L1.Oberösterreich 0.409778 0.158705 2.582 0.010
L1.Salzburg 0.288264 0.083166 3.466 0.001
L1.Steiermark 0.107502 0.108510 0.991 0.322
L1.Tirol 0.311359 0.088012 3.538 0.000
L1.Vorarlberg 0.026042 0.075902 0.343 0.732
L1.Wien -0.028374 0.140423 -0.202 0.840
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189116 0.029012 6.519 0.000
L1.Burgenland 0.089981 0.019013 4.733 0.000
L1.Kärnten -0.008761 0.010082 -0.869 0.385
L1.Niederösterreich 0.263283 0.039832 6.610 0.000
L1.Oberösterreich 0.138095 0.038818 3.557 0.000
L1.Salzburg 0.045861 0.020342 2.255 0.024
L1.Steiermark 0.020572 0.026541 0.775 0.438
L1.Tirol 0.092569 0.021527 4.300 0.000
L1.Vorarlberg 0.056012 0.018565 3.017 0.003
L1.Wien 0.114499 0.034347 3.334 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.111566 0.029550 3.775 0.000
L1.Burgenland 0.045891 0.019366 2.370 0.018
L1.Kärnten -0.014005 0.010269 -1.364 0.173
L1.Niederösterreich 0.189074 0.040571 4.660 0.000
L1.Oberösterreich 0.301397 0.039539 7.623 0.000
L1.Salzburg 0.109543 0.020719 5.287 0.000
L1.Steiermark 0.104536 0.027033 3.867 0.000
L1.Tirol 0.105556 0.021927 4.814 0.000
L1.Vorarlberg 0.067925 0.018910 3.592 0.000
L1.Wien -0.022077 0.034984 -0.631 0.528
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.130546 0.053834 2.425 0.015
L1.Burgenland -0.049687 0.035281 -1.408 0.159
L1.Kärnten -0.040802 0.018708 -2.181 0.029
L1.Niederösterreich 0.166089 0.073911 2.247 0.025
L1.Oberösterreich 0.140292 0.072031 1.948 0.051
L1.Salzburg 0.288968 0.037746 7.656 0.000
L1.Steiermark 0.036317 0.049249 0.737 0.461
L1.Tirol 0.163032 0.039946 4.081 0.000
L1.Vorarlberg 0.099359 0.034449 2.884 0.004
L1.Wien 0.068197 0.063733 1.070 0.285
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.055886 0.042824 1.305 0.192
L1.Burgenland 0.039297 0.028065 1.400 0.161
L1.Kärnten 0.051347 0.014882 3.450 0.001
L1.Niederösterreich 0.218061 0.058795 3.709 0.000
L1.Oberösterreich 0.296462 0.057299 5.174 0.000
L1.Salzburg 0.043670 0.030026 1.454 0.146
L1.Steiermark 0.001105 0.039176 0.028 0.977
L1.Tirol 0.142454 0.031776 4.483 0.000
L1.Vorarlberg 0.072277 0.027403 2.638 0.008
L1.Wien 0.080282 0.050698 1.584 0.113
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.175378 0.051163 3.428 0.001
L1.Burgenland -0.002800 0.033531 -0.083 0.933
L1.Kärnten -0.062532 0.017780 -3.517 0.000
L1.Niederösterreich -0.080995 0.070244 -1.153 0.249
L1.Oberösterreich 0.191636 0.068457 2.799 0.005
L1.Salzburg 0.057832 0.035874 1.612 0.107
L1.Steiermark 0.235510 0.046806 5.032 0.000
L1.Tirol 0.498165 0.037964 13.122 0.000
L1.Vorarlberg 0.044850 0.032740 1.370 0.171
L1.Wien -0.054633 0.060572 -0.902 0.367
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.172551 0.058805 2.934 0.003
L1.Burgenland -0.007323 0.038539 -0.190 0.849
L1.Kärnten 0.066077 0.020435 3.233 0.001
L1.Niederösterreich 0.205948 0.080736 2.551 0.011
L1.Oberösterreich -0.070625 0.078682 -0.898 0.369
L1.Salzburg 0.207322 0.041232 5.028 0.000
L1.Steiermark 0.122211 0.053797 2.272 0.023
L1.Tirol 0.071448 0.043634 1.637 0.102
L1.Vorarlberg 0.117410 0.037630 3.120 0.002
L1.Wien 0.117135 0.069619 1.683 0.092
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.362068 0.033883 10.686 0.000
L1.Burgenland 0.007364 0.022205 0.332 0.740
L1.Kärnten -0.023653 0.011775 -2.009 0.045
L1.Niederösterreich 0.218561 0.046519 4.698 0.000
L1.Oberösterreich 0.198134 0.045335 4.370 0.000
L1.Salzburg 0.042796 0.023757 1.801 0.072
L1.Steiermark -0.014078 0.030997 -0.454 0.650
L1.Tirol 0.104608 0.025141 4.161 0.000
L1.Vorarlberg 0.070051 0.021682 3.231 0.001
L1.Wien 0.036330 0.040113 0.906 0.365
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.039885 0.138327 0.190515 0.150484 0.117326 0.102790 0.061645 0.215625
Kärnten 0.039885 1.000000 -0.006745 0.132675 0.038898 0.094512 0.433670 -0.053888 0.098113
Niederösterreich 0.138327 -0.006745 1.000000 0.334128 0.141099 0.293748 0.094463 0.175477 0.313371
Oberösterreich 0.190515 0.132675 0.334128 1.000000 0.227704 0.324635 0.174892 0.163262 0.260409
Salzburg 0.150484 0.038898 0.141099 0.227704 1.000000 0.141992 0.111321 0.143296 0.123300
Steiermark 0.117326 0.094512 0.293748 0.324635 0.141992 1.000000 0.145758 0.136803 0.070697
Tirol 0.102790 0.433670 0.094463 0.174892 0.111321 0.145758 1.000000 0.110442 0.141997
Vorarlberg 0.061645 -0.053888 0.175477 0.163262 0.143296 0.136803 0.110442 1.000000 -0.003283
Wien 0.215625 0.098113 0.313371 0.260409 0.123300 0.070697 0.141997 -0.003283 1.000000